package LogisticsSystem.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import LogisticsSystem.po.Orders;
import LogisticsSystem.po.Orderdetail;
import LogisticsSystem.po.Staff;
import LogisticsSystem.service.ServiceStaffService;
import LogisticsSystem.service.StaffService;

@Controller
@RequestMapping("serviceStaff")
public class ServiceStaffController {
	@Autowired
	private ServiceStaffService serviceStaffService;
	@Autowired
	private StaffService staffService;

	// 1.查看所有派送请求
	@RequestMapping("/showOrder")
	public String showOrder(HttpServletRequest request) throws Exception {
		Staff staff = (Staff) request.getSession().getAttribute("staff");
		if (staff.getsRole().equals("4")) {
			request.getSession().setAttribute("OrderList", serviceStaffService.showOrderExtend0());
			return "customer/serviceStaff";// 跳回客服的主页

		}
		request.getSession().setAttribute("error", "error");
		return "redirect:Backstage.jsp";// 也是跳回主页

	}

	// 2.跳转生成订单界面
	@RequestMapping("/creatOrder")
	public String createOrderJump(Orders order, Model model) throws Exception {
		if (order == null) {
			model.addAttribute("tip", "当前没有传入配送请求");
			return "error";
		}
		List<Orderdetail> orderdetails = serviceStaffService.showOrderDetailByOrderId(order.getcId());
		if (orderdetails.size() == 0) {
			model.addAttribute("tip", "商品信息获取失败");
			return "error";
		}
		model.addAttribute("orderdetails", orderdetails);
		model.addAttribute("order", order);
		return "";// 跳转到生成订单界面
	}

	// 3.接受派送请求生成订单
	@RequestMapping("/creatOrder1")
	public String createOrder(Orders order, Model model) throws Exception {
		if (order == null) {
			model.addAttribute("tip", "生成订单失败");
			return "error";
		}

		return "";// 跳转到生成订单界面
	}
	// 3.根据中央库房情况确定订单状态
}
